package com.lscl.rabbitmq;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.config.ListenerContainerFactoryBean;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class);
    }

    /**
     * 监听容器
     * @param connectionFactory
     * @return
     */
    @Bean
    public ListenerContainerFactoryBean factoryBean(ConnectionFactory connectionFactory){
        ListenerContainerFactoryBean bean=new ListenerContainerFactoryBean();
        bean.setConnectionFactory(connectionFactory);
        // 手动签收
//        bean.setAcknowledgeMode(AcknowledgeMode.MANUAL);

        // 每次从队列中拉取一条消息消费
//        bean.setPrefetchCount(1);
        return bean;
    }
}